home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / sql-bench / innotest1 < prev    next >
Encoding:
Text File  |  2003-01-22  |  4.8 KB  |  142 lines  |  [TEXT/ttxt]

  1. #!/usr/bin/perl
  2. ############################################################################
  3. #     Stress test for MySQL/InnoDB combined database
  4. #     (c) 2002 Innobase Oy & MySQL AB
  5. #
  6. ############################################################################
  7.  
  8. use DBI;
  9. use Benchmark;
  10.  
  11. $opt_loop_count = 100000;
  12.  
  13. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  14. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  15.  
  16. print "Innotest1: MySQL/InnoDB stress test in Perl\n";
  17. print "-------------------------------------------\n";
  18. print "This is a randomized stress test for concurrent inserts,\n";
  19. print "updates, deletes, commits and rollbacks. The test will generate\n";
  20. print "also a lot of deadlocks, duplicate key errors, and other SQL errors.\n";
  21. print "\n";
  22. print "You should run innotest1, innotest1a, and innotest1b concurrently.\n";
  23. print "The thing to watch is that the server does not crash or does not\n";
  24. print "print to the .err log anything. Currently, due to a buglet in MySQL,\n";
  25. print "warnings about MySQL lock reservations can appear in the .err log.\n";
  26. print "The test will run very long, even several hours. You can kill\n";
  27. print "the perl processes running this test at any time and do CHECK\n";
  28. print "TABLE on table innotest1 in the 'test' database.\n";
  29. print "\n";
  30. print "Some of these stress tests will print a lot of SQL errors\n";
  31. print "to the standard output. That is not to be worried about.\n";
  32. print "You can direct the output to a file like this:\n";
  33. print "perl innotest1 > out1\n\n";
  34.      
  35. print "Generating random keys\n";
  36. $random[$opt_loop_count] = 0;
  37. $rnd_str[$opt_loop_count] = "a";
  38.  
  39. for ($i = 0; $i < $opt_loop_count; $i++) {
  40.  
  41.     $random[$i] = ($i * 63857) % $opt_loop_count;
  42.  
  43.       if (0 == ($random[$i] % 3)) {
  44.           $rnd_str[$i] = "kjgclgrtfuylfluyfyufyulfulfyyulofuyolfyufyufuyfyufyufyufyufyyufujhfghd";
  45.     } else { if (1 == ($random[$i] % 3)) {
  46.         $rnd_str[$i] = "khd";
  47.     } else { if (2 == ($random[$i] % 3)) {
  48.         $rnd_str[$i] = "kh";
  49.     }}}
  50.  
  51.     for ($j = 0; $j < (($i * 764877) % 20); $j++) {
  52.         $rnd_str[$i] = $rnd_str[$i]."k";
  53.     }    
  54. }
  55.  
  56. ####
  57. ####  Connect
  58. ####
  59.  
  60. $dbh = $server->connect()
  61. || die $dbh->errstr;
  62.  
  63. $dbh->do("set autocommit = 0");
  64.  
  65. $n = 0;
  66.  
  67. for ($i = 0; $i < 1; $i++) {
  68.  
  69.     print "Dropping table innotest1\n";
  70.  
  71.     $dbh->do("drop table innotest1");
  72.  
  73.     print "Creating table innotest1\n";
  74.  
  75.     $dbh->do(
  76.     "create table innotest1 (A INT NOT NULL AUTO_INCREMENT, D INT NOT NULL, B VARCHAR(200) NOT NULL, C VARCHAR(175), E TIMESTAMP, F TIMESTAMP, G DATETIME, PRIMARY KEY (A, D), INDEX
  77. (B, C), INDEX (C), INDEX (D), INDEX(E), INDEX(G)) TYPE = INNODB")
  78.     || die $dbh->errstr;
  79.  
  80.     for ($j = 2; $j < $opt_loop_count - 10; $j = $j + 2) {
  81.  
  82.         if ($j % 10 == 0) {
  83.             $dbh->do(
  84.         "insert into innotest1 (D, B, C, F, G) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."', NULL, NULL)");
  85.         } else {
  86.             $dbh->do(
  87.         "insert into innotest1 (D, B, C, F, G) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."', NOW(), NOW())");
  88.         }
  89.  
  90.         $dbh->do("update innotest1 set B = '".$rnd_str[$j + 7]."' where A = ".$random[$j + 5]);
  91.  
  92.         $dbh->do("update innotest1 SET D = D + 1 where A =".($j / 2 - 500));
  93.  
  94.         $dbh->do("update innotest1 set B = '".$rnd_str[$j + 1]."' where A =".($j / 2 - 505));
  95.  
  96.         $dbh->do("delete from innotest1 where A = ".$random[$random[$j]]);
  97.         
  98.         fetch_all_rows($dbh, "select b, c from innotest1 where a > ".$random[$j]." and a < ".($random[$j] + 7));
  99.         
  100.         if (0 == ($j % 10)) {
  101.             $dbh->do("commit");
  102.         }
  103.  
  104.         if (0 == ($j % 97)) {
  105.         fetch_all_rows($dbh, "select c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
  106.         fetch_all_rows($dbh, "select b, e, f, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
  107.         fetch_all_rows($dbh, "select b, c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
  108.         fetch_all_rows($dbh, "select b, c, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
  109.         fetch_all_rows($dbh, "select a, b, c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
  110.         fetch_all_rows($dbh, "select a, b, c, e, f, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
  111.         fetch_all_rows($dbh, "select d, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
  112.         fetch_all_rows($dbh, "select d, b, c, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
  113.  
  114.             $dbh->do("rollback");
  115.         }        
  116.  
  117.             for ($k = 1; $k < 10; $k++) {
  118.  
  119.                     $n += fetch_all_rows($dbh,
  120. "SELECT a, d from innotest1 where a = ".(($k * 1764767) % $j));
  121.  
  122.                     $n += fetch_all_rows($dbh,
  123. "SELECT * from innotest1 where a = ".(($k * 187567) % $j));
  124.  
  125.             }
  126.  
  127.         if (0 == ($j % 1000)) {
  128.             print "round $j, $n rows fetched\n";
  129.         }
  130.  
  131.         if (0 == ($j % 20000)) {
  132.             print "Checking table innotest1...\n";
  133.             $dbh->do("check table innotest1");
  134.             print "Table checked.\n";
  135.         }
  136.     }    
  137.     
  138.     $dbh->do("commit");
  139. }                
  140.  
  141. $dbh->disconnect;                # close connection
  142.